﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mime;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JobbJakt;

namespace JobbJaktWeb
{
    public partial class DeleteHeadHunter : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }

        protected void ButtonRemoveUser_Click(object sender, EventArgs e)
        {
            try
            {
                var user = Users.PrintUser(TextBoxUserName.Text.Trim());

                if (user != null)
                {
                    Users.RemoveUser(user.UserName);
                    LabelUserInActivated.Visible = true;
                }
                else
                {
                    LabelUserNonExisting.Visible = true;
                }
            }
            catch (Exception ex)
            {
                ErrorTable newErrorTable = new ErrorTable() { Message = ex.Message, Type = ex.GetType().ToString() };
                ErrorTable.InsertError(newErrorTable);
                throw new Exception();
            }
        }

        protected void ButtonAddHeadHunter_Click(object sender, EventArgs e)
        {
            try
            {
                if (Users.UserExist(TextBoxUserNameAdd.Text.Trim()))
                {
                    bool aktiv = RadioButtonActive.Checked;

                    Users newUsers = new Users()
                    {
                        UserName = TextBoxUserNameAdd.Text.Trim(),
                        SocialSecurityNumber = TextBoxAddSocialSecNumber.Text.Trim(),
                        Password = TextBoxAddPassWord.Text.Trim(),
                        Authorization = (Authorization)int.Parse(DropDownList1.SelectedValue),
                        FirstName = TextBoxAddFirstName.Text.Trim(),
                        LastName = TextBoxAddLastName.Text.Trim(),
                        Address = TextBoxAddAddress.Text.Trim(),
                        ZipCode = TextBoxAddZipCode.Text.Trim(),
                        City = TextBoxAddCity.Text.Trim(),
                        Phone = TextBoxAddTelePhoneNumber.Text.Trim(),
                        Email = TextBoxEMail.Text.Trim(),
                        Interest = " ",
                        Attributes = " ",
                        RegistrationDate = DateTime.Today,
                        Active = aktiv,
                        DriversLicense = false

                    };
                    Users.UpdateUser(newUsers);
                    LabelHeadHunterActivated.Visible = true;
                }
                
            }
            catch (Exception ex)
            {
                ErrorTable newErrorTable = new ErrorTable() { Message = ex.Message, Type = ex.GetType().ToString() };
                ErrorTable.InsertError(newErrorTable);
                throw new Exception();
            }
            
        }

        protected void ButtonGetHeadHunter_Click(object sender, EventArgs e)
        {
            if (TextBoxUserNameAdd.Text != null)
            {
                FillTextBoxes();
            }
            
        }

        public void FillTextBoxes()
        {
            var user = Users.PrintUser(TextBoxUserNameAdd.Text.Trim());
         
                TextBoxAddSocialSecNumber.Text = user.SocialSecurityNumber;
                TextBoxAddPassWord.Text = user.Password;
                TextBoxAddFirstName.Text = user.FirstName;
                TextBoxAddLastName.Text = user.LastName;
                TextBoxAddAddress.Text = user.Address;
                TextBoxAddZipCode.Text = user.ZipCode;
                TextBoxAddCity.Text = user.City;
                TextBoxAddTelePhoneNumber.Text = user.Phone;
                TextBoxEMail.Text = user.Email;
           
        }



    }
}